package com.ctshk.rpc.order.custom.mapper;


import com.ctshk.rpc.order.custom.base.CustomBaseMapper;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderReceiptTourist;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 收据关联游客 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
public interface CustomizedOrderReceiptTouristMapper extends CustomBaseMapper<CustomizedOrderReceiptTourist> {

    /**
     * 获取旅客保险收据
     * @param orderId
     * @param touristId
     * @return
     */
    @Select("SELECT a.* \n" +
            "FROM t_customized_order_receipt_tourist a\n" +
            "LEFT JOIN t_customized_order_receipt b ON a.receipt_id = b.id\n" +
            "WHERE a.order_id = #{order_id} AND a.tourist_id = #{tourist_id} AND b.receipt_type = 2 LIMIT 1")
    CustomizedOrderReceiptTourist queryTouristInsuranceReceipt(@Param("order_id") Long orderId, @Param("tourist_id") Long touristId);

    /**
     * 清空订单收据关联旅客
     * @param orderId
     * @param userId
     */
    @Update("UPDATE t_customized_order_receipt_tourist\n" +
            "SET is_deleted = 1,modified_id = #{user_id}\n" +
            "WHERE order_id = #{order_id} AND is_deleted = 0")
    void cleanByOrder(@Param("order_id") Long orderId, @Param("user_id") Long userId);
}
